package com.itheima.JDBC;

import java.sql.*;

public class user {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.获取链接
        String url = "jdbc:mysql://127.0.0.1:3306/db01";
        String username = "root";
        String password = "328802";
        Connection connection = DriverManager.getConnection(url, username, password);
        String name = "zhangsan";
        String pwd = "666";
        String sql = "select * from tb_user where username = ?  and password =?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, name);
        preparedStatement.setString(2, pwd);
        ResultSet rs = preparedStatement.executeQuery();
        if (rs.next()) {
            System.out.println("登录成功");
        } else {
            System.out.println("登录失败");
        }
        preparedStatement.close();
        connection.close();
    }
}
